<script>
import Vue from 'vue';
const API = require('./utils/api/user.js').default;
const app = require('./utils/app.js').default;
const $ = require('./utils/api.js');
// #ifdef H5
var wx = require('./utils/jweixin-module.js');
// #endif
// const VConsole = require('./utils/vconsole.js');
//import './utils/vconsole.js';
// const JMessage = require('./utils/jmessage-wxapplet-sdk-1.4.2.min.js');

import indexConfig from '@/config/index.config';
// let appRole = 'daxiang';
import { mapMutations } from 'vuex';

export default {
	globalData: {
		// appRole: appRole,
		name:  indexConfig.name,
		version:  indexConfig.version,
		api:  indexConfig.baseUrl,
		hot:indexConfig.hot,
		socket:  indexConfig.socket ?  indexConfig.socket : '',
		appKey:   indexConfig.appKey,
		appSecret:   indexConfig.appSecret,
		mapKey:   indexConfig.qqmapKey,//腾讯地图key
		amapKey:   indexConfig.amapKey,
		height: 0,
		inviteCode: '',
		isWeiXin: false,
		openfind: false
	},
	/**
	 * 用户点击右上角分享
	 */
	// #ifdef MP
	onShareAppMessage: function() {
		return {
			title: "",
			imageUrl: '',
			path: `/pages/home/index?id=0&inviteCode=${this.globalData.inviteCode}` ,
		}
	},
	onShareTimeline: function() {
		  return {
			title: "",
			imageUrl: '',
			path: `/pages/home/index?id=0&inviteCode=${this.globalData.inviteCode}` 
		}
	},
	// #endif
	onLaunch: function(options) {
		const self = this;

		this.globalData.inviteCode = options.query.inviteCode ? options.query.inviteCode : '';
		// #ifdef H5
			if (window.location.href.indexOf('pages/user/passport/down') >= 0) {
				return;//通过下载链接进来的无需进行授权
			}
			// if(this.isWeiXin()) {
			// 	wx.ready(function(){
			// 		// TODO
			// 	});
			// 	if(!uni.getStorageSync('token')){
			// 		$.wxAuthH5(options.query.inviteCode ? options.query.inviteCode : '');
			// 	}
			// 	if (window.location.href.indexOf('from') >= 0) {
			// 		this.h5Reload();
			// 	}

			// }
		// #endif

		// var vConsole = new VConsole();
		// console.log('App Launch');
		// let JIM = new JMessage({
		// 	debug: false
		// });
		// this.globalData.JIM = JIM;
		uni.getSystemInfo({
			success(e) {

				self.globalData.height = e.windowHeight;
				// #ifndef MP
				Vue.prototype.StatusBar = e.statusBarHeight;
				if (e.platform === 'android') {
					Vue.prototype.CustomBar = e.statusBarHeight ;
				} else {
					Vue.prototype.CustomBar = e.statusBarHeight;
				}
				// #endif
				// #ifdef MP-WEIXIN
				Vue.prototype.StatusBar = e.statusBarHeight;
				// eslint-disable-next-line
				const custom = wx.getMenuButtonBoundingClientRect();
				Vue.prototype.Custom = custom;
				Vue.prototype.CustomBar = custom.top - e.statusBarHeight;
				// #endif
				// #ifdef MP-ALIPAY
				Vue.prototype.StatusBar = e.statusBarHeight;
				Vue.prototype.CustomBar = e.statusBarHeight + e.titleBarHeight;
				// #endif
				uni.setStorageSync('bartop', Vue.prototype.StatusBar);

				 if (e.platform == 'ios') {
					let nav_top = Number(e.statusBarHeight);
			// uni.setStorageSync('bartop', nav_top)
					uni.setStorageSync('isIos', true);
				} else if (e.platform == 'android') {
					let nav_top = Number(e.statusBarHeight);
					// uni.setStorageSync('bartop', nav_top);
					uni.setStorageSync('isIos', false);
				}

				let safeArea = ['iPhone8','iPhone8Pro','iPhone7','iPhone7Pro','iPhone6','iPhone6Pro','iPhone5','iPhoneSE'];
				if(e.platform == 'ios') {
					// #ifndef H5
					uni.setStorageSync('isIphonex', true);
					// #endif
					safeArea.forEach((ele,index) => {
						if(e.model && e.model.indexOf(ele) >= 0) {
							uni.setStorageSync('isIphonex', false);
						}
					})
				}
				uni.setStorageSync('model', e.model);
			}
		});



		this.getKefuId();
		self.socket.creatSocket({
			onMessage(res) {
			}
		})

		// await this.initData();
		 this.initData();

	},

	methods: {
		...mapMutations(['setCartNum', 'setNotifyNum']),
		async initData() {

			// 获取系统title高度
			await this.initSystemInfo();

			this.setCartNum(uni.getStorageSync('cartNum') || 0);
			this.setNotifyNum(uni.getStorageSync('notifyNum') || 0);
		},
		// 初始化系统信息
		initSystemInfo() {
			uni.getSystemInfo({
				success(e) {
					// #ifndef MP
					Vue.prototype.StatusBar = e.statusBarHeight;
					if (e.platform === 'android') {
						Vue.prototype.CustomBar = e.statusBarHeight + 50;
					} else {
						Vue.prototype.CustomBar = e.statusBarHeight + 43;
					}
					// #endif
					// #ifdef MP-WEIXIN
					Vue.prototype.StatusBar = e.statusBarHeight;
					// eslint-disable-next-line
					const custom = wx.getMenuButtonBoundingClientRect();
					Vue.prototype.Custom = custom;
					Vue.prototype.CustomBar = custom.top - e.statusBarHeight;
					// #endif
					// #ifdef MP-ALIPAY
					Vue.prototype.StatusBar = e.statusBarHeight;
					Vue.prototype.CustomBar = e.statusBarHeight + e.titleBarHeight;
					// #endif
				}
			});
		},
		getWxConfig() {
			const self = this;
			$.ajax({
				url: 'common/wechatParam',
				data: {
					url: 'https://h5.ccchongya.com/#/',
				},
				method: 'GET',
				success(res) {
				},
				complete(data) {
					if(data.signature) {
						wx.config({
							debug: false, ////生产环境需要关闭debug模式
							appId: data.appid, //appId通过微信服务号后台查看
							timestamp: data.timestamp, //生成签名的时间戳
							nonceStr: data.nonceStr, //生成签名的随机字符串
							signature: data.signature, //签名
							jsApiList: [ //需要调用的JS接口列表
								'checkJsApi', //判断当前客户端版本是否支持指定JS接口
								'onMenuShareTimeline', //分享给好友
								'onMenuShareAppMessage', //分享到朋友圈
								'scanQRCode',
								'getLocation'
							],
							openTagList: ['wx-open-launch-weapp']
						});
						// self.share();
					}
				}
			})
		},
		shareWx() {
			const self = this;
			let data = uni.getStorageSync('config') ? uni.getStorageSync('config') : '';
			let user = uni.getStorageSync('userInfo') ? uni.getStorageSync('userInfo') : '';
			let link = data.h5_url + '/#/pages/home/index?inviteCode=';//h5不享受邀请奖励政策
			if(user != '') {
				link = link + user.id;
			}
			// let link = data.h5_url + '/#/pages/home/index';
			wx.ready(function() {
				// 2.1 监听“分享给朋友”，按钮点击、自定义分享内容及分享结果接口
				wx.onMenuShareTimeline({
					title: data.web_name ? data.web_name : '米兔',
					link: link,
					imgUrl: data.logo ? data.logo : 'https://qiniu.chengyuwb.com/xss-share.jpg',
					desc: data.spread_content ? data.spread_content : '', // 分享描述
					success: function(res) {
						//share();
					}
				});
				//分享到朋友圈
				wx.onMenuShareAppMessage({
					title: data.web_name ? data.web_name : '米兔',
					link: link,
					imgUrl: data.logo ? data.logo : 'https://qiniu.chengyuwb.com/xss-share.jpg',
					desc: data.spread_content ? data.spread_content : '', // 分享描述
					success: function(res) {
						//share();
					}
				});
			});
		},
		 isWeiXin(){
		    var ua = window.navigator.userAgent.toLowerCase();
		    if(ua.match(/MicroMessenger/i) == 'micromessenger'){
				this.globalData.isWeiXin = true;
		        return true;
		    }else{
		        return false;
		    }
		},
		getStyleConfig() {
			const self = this;
			$.ajax({
				url: 'common/globalStyle/get',
				data: {},
				method: 'GET',
				success(res) {
					let info = res.data;
					setTimeout(() => {
						uni.setStorageSync('styleConfig', res.data);
					},1000)
				}
			});
		},

		getCache(key){
		    let val = uni.getStorageSync(key)
		    if (!val) {
		      return null
		    }
		    val = JSON.parse(val)
		    console.log('pre setCache:',val.data)
		    if (val.expire && Date.now() / 1000 - val.time > val.expire) {
		      uni.removeStorageSync(key)
		      return null
		    }
		    console.log('end setCache:',val.data)
		    return val.data
		},
	   setCache(key, value, expire = 0){
		    let obj = {
		      data: value, //存储的数据
		      time: Date.now() / 1000, //记录存储的时间戳
		      expire: expire //记录过期时间，单位秒
		    }
		    console.log('setCache:',value)
		    uni.setStorageSync(key, JSON.stringify(obj))
		},
		getConfig() {
			const self = this;
			$.ajax({
				url: 'common/config/getList',
				data: {},
				method: 'GET',
				success(res) {
					let info = res.data;
			
	
					uni.setStorageSync('appconfig', res.data);
					// #ifdef H5
					if(self.globalData.isWeiXin){
						self.getWxConfig();
					}
					// #endif
					if(info.language != 'all' && info.language != 'folowSystem') {
						self.changeLang(info.language)
					}
				}
			});
		},
		getUser() {

				console.log("getUser")
			const self = this;
			$.ajax({
				url: 'member/getUser',
				isAuth: true,
				data: {},
				method: 'GET',
				success(res) {
					let info = res.data ? res.data : '';
					if(!info.phone) {
						self.go('/pages/wxAuth/bindphone')
					}
				}
			})
		},
		getKefuId() {
			$.ajax({
				url: API.getKefuIdApi,
				data: {},
				method: 'GET',
				success(res) {
					let info = res.data ? res.data : '';
					if(info == ''){return;}
					uni.setStorageSync('kefuId',info);
				}
			})
		},
	},
	onShow: function() {
		this.getConfig();
		this.getStyleConfig();
	},
	onHide: function() {
		// console.log('App Hide');
	}
};
</script>




<style>
@import './static/css/uni.css';
@import './static/css/icon.css';
@import './static/css/color.css';
@import './static/css/common.css';
@import './static/css/animate.css';
/* 解决头条小程序组件内引入字体不生效的问题 */
/* #ifdef MP-TOUTIAO */
@font-face {
	font-family: uniicons;
	src: url('/static/uni.ttf');
}
/* #endif */


page{background: #F8F8F8;}

</style>


<style  lang="scss">
@import './static/iconfont/iconfont.css';
		/* 注意要写在第一行，同时给style标签加入lang="scss"属性 */
/* 注意要写在第一行，同时给style标签加入lang="scss"属性 */
@import "uview-ui/index.scss";
/* //code.fun生成的全局 */
@import './static/css/style.css';


// 导入阿里巴巴矢量图标库
/*#ifdef MP*/
@import './static/iconfont/iconfont.css';
// @import './static/css/iconfont/myfont.css';
/*#endif*/
/*#ifndef MP*/
@import url('https://at.alicdn.com/t/font_1681579_dwilkcq6mvg.css');
/*#endif*/
/*#ifndef MP*/
// @import 'https://netdna.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css';
/*#endif*/

// @import './static/css/reset.scss';
// @import './static/css/uni.scss';

@import './uview-ui/index.scss';
// @import './uview-ui/iconfont.css';
	
	
.acea-row {
	display: flex;
	flex-wrap: row;
    justify-content: space-between
}
.row-middle{
	align-items: center;
}


	.lxwm {
	  margin-top: 38rpx;
	  background-image: linear-gradient(90deg, #edf5ff 0%, #92dbf000 100%);
	  border-radius: 10rpx;
	  overflow: hidden;
	}
	.lxwm .image_8 {
	  width: 702rpx;
	  height: 136rpx;
	}
	.lxwm .text_13 {
	  color: #0000008a;
	}
	.lxwm .pos_8 {
	  position: absolute;
	  left: 17rpx;
	  top: 26rpx;
	}
	.lxwm .text_14 {
	  color: #4578ff;
	  font-size: 52rpx;
	  font-family: DIN;
	  font-weight: 900;
	  line-height: 38rpx;
	}
	.lxwm .pos_9 {
	  position: absolute;
	  left: 17rpx;
	  bottom: 27rpx;
	}
	.lxwm .image_9 {
	  width: 124rpx;
	  height: 108rpx;
	}
	.lxwm .pos_7 {
	  position: absolute;
	  right: 28rpx;
	  top: 50%;
	  transform: translateY(-50%);
	}
</style>

